package mysql

import (
	"gorm.io/gorm"
)

type Technician struct {
	gorm.Model
	Name   string  `gorm:"type:varchar(20);not null;uniper;comment:姓名"`
	Age    int     `gorm:"type:int(11);not null;default:0;comment:年龄"`
	Sex    string  `gorm:"type:enum('男','女');not null;comment:性别"`
	Mobile string  `gorm:"type:char(11);not null;uniper;comment:手机号"`
	Images string  `gorm:"type:varchar(255);not null;comment:头像"`
	Price  float64 `gorm:"type:float(10,2);not null;comment:价格"`
	Num    int     `gorm:"type:int(10);not null;comment:库存"`
}

func (t *Technician) Create() error {
	return db.Create(&t).Error
}

func SyneMobile(mobile string) string {
	mobile = `$/1[1-3]{0-9}[2]/^`
	return mobile
}

/*func (t *Technician) List(name string) error {
	return db.Where("name = ?", name).First(&t).Error

}
func Paginate(page, perPage string) func(db *gorm.DB) *gorm.DB {
	return func(db *gorm.DB) *gorm.DB {

		page, _ := strconv.Atoi(page.Get("page"))
		if page <= 0 {
			page = 1
		}

		pageSize, _ := strconv.Atoi(perPage.Get("page_size"))
		switch {
		case pageSize > 100:
			pageSize = 100
		case pageSize <= 0:
			pageSize = 10
		}

		offset := (page - 1) * pageSize
		return db.Offset(offset).Limit(pageSize)
	}
}

func (t *Technician) ListT() {
	db.Where("price = ?", price).Where("num = ?", num).Order("dect").Find(&t)
}
*/
